<template>
  <el-dialog
    :title="!dataForm.refundId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单编号" prop="orderNum">
      <el-input v-model="dataForm.orderNum" placeholder="订单编号"></el-input>
    </el-form-item>
    <el-form-item label="退款金额" prop="refundPrice">
      <el-input v-model="dataForm.refundPrice" placeholder="退款金额"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="是否删除" prop="delStatus">
      <el-input v-model="dataForm.delStatus" placeholder="是否删除"></el-input>
    </el-form-item>
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="房源类型" prop="homeType">
      <el-input v-model="dataForm.homeType" placeholder="房源类型"></el-input>
    </el-form-item>
    <el-form-item label="第三方交易流水号" prop="threeDeal">
      <el-input v-model="dataForm.threeDeal" placeholder="第三方交易流水号"></el-input>
    </el-form-item>
    <el-form-item label="业务类型" prop="studyType">
      <el-input v-model="dataForm.studyType" placeholder="业务类型"></el-input>
    </el-form-item>
    <el-form-item label="第三方状态码" prop="threeStatus">
      <el-input v-model="dataForm.threeStatus" placeholder="第三方状态码"></el-input>
    </el-form-item>
    <el-form-item label="第三方错误信息" prop="threeError">
      <el-input v-model="dataForm.threeError" placeholder="第三方错误信息"></el-input>
    </el-form-item>
    <el-form-item label="支付渠道（支付宝 微信 银行卡）" prop="orderChannel">
      <el-input v-model="dataForm.orderChannel" placeholder="支付渠道（支付宝 微信 银行卡）"></el-input>
    </el-form-item>
    <el-form-item label="退款成功时间" prop="successTime">
      <el-input v-model="dataForm.successTime" placeholder="退款成功时间"></el-input>
    </el-form-item>
    <el-form-item label="审核id" prop="checkId">
      <el-input v-model="dataForm.checkId" placeholder="审核id"></el-input>
    </el-form-item>
    <el-form-item label="审核记录id" prop="recordId">
      <el-input v-model="dataForm.recordId" placeholder="审核记录id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          refundId: 0,
          orderNum: '',
          refundPrice: '',
          createTime: '',
          updateTime: '',
          delStatus: '',
          userId: '',
          homeType: '',
          threeDeal: '',
          studyType: '',
          threeStatus: '',
          threeError: '',
          orderChannel: '',
          successTime: '',
          checkId: '',
          recordId: ''
        },
        dataRule: {
          orderNum: [
            { required: true, message: '订单编号不能为空', trigger: 'blur' }
          ],
          refundPrice: [
            { required: true, message: '退款金额不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          delStatus: [
            { required: true, message: '是否删除不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          homeType: [
            { required: true, message: '房源类型不能为空', trigger: 'blur' }
          ],
          threeDeal: [
            { required: true, message: '第三方交易流水号不能为空', trigger: 'blur' }
          ],
          studyType: [
            { required: true, message: '业务类型不能为空', trigger: 'blur' }
          ],
          threeStatus: [
            { required: true, message: '第三方状态码不能为空', trigger: 'blur' }
          ],
          threeError: [
            { required: true, message: '第三方错误信息不能为空', trigger: 'blur' }
          ],
          orderChannel: [
            { required: true, message: '支付渠道（支付宝 微信 银行卡）不能为空', trigger: 'blur' }
          ],
          successTime: [
            { required: true, message: '退款成功时间不能为空', trigger: 'blur' }
          ],
          checkId: [
            { required: true, message: '审核id不能为空', trigger: 'blur' }
          ],
          recordId: [
            { required: true, message: '审核记录id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.refundId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.refundId) {
            this.$http({
              url: this.$http.adornUrl(`/system/systemrefundorder/info/${this.dataForm.refundId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderNum = data.systemRefundOrder.orderNum
                this.dataForm.refundPrice = data.systemRefundOrder.refundPrice
                this.dataForm.createTime = data.systemRefundOrder.createTime
                this.dataForm.updateTime = data.systemRefundOrder.updateTime
                this.dataForm.delStatus = data.systemRefundOrder.delStatus
                this.dataForm.userId = data.systemRefundOrder.userId
                this.dataForm.homeType = data.systemRefundOrder.homeType
                this.dataForm.threeDeal = data.systemRefundOrder.threeDeal
                this.dataForm.studyType = data.systemRefundOrder.studyType
                this.dataForm.threeStatus = data.systemRefundOrder.threeStatus
                this.dataForm.threeError = data.systemRefundOrder.threeError
                this.dataForm.orderChannel = data.systemRefundOrder.orderChannel
                this.dataForm.successTime = data.systemRefundOrder.successTime
                this.dataForm.checkId = data.systemRefundOrder.checkId
                this.dataForm.recordId = data.systemRefundOrder.recordId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/system/systemrefundorder/${!this.dataForm.refundId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'refundId': this.dataForm.refundId || undefined,
                'orderNum': this.dataForm.orderNum,
                'refundPrice': this.dataForm.refundPrice,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'delStatus': this.dataForm.delStatus,
                'userId': this.dataForm.userId,
                'homeType': this.dataForm.homeType,
                'threeDeal': this.dataForm.threeDeal,
                'studyType': this.dataForm.studyType,
                'threeStatus': this.dataForm.threeStatus,
                'threeError': this.dataForm.threeError,
                'orderChannel': this.dataForm.orderChannel,
                'successTime': this.dataForm.successTime,
                'checkId': this.dataForm.checkId,
                'recordId': this.dataForm.recordId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
